﻿using System;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace MpSoft.Library.CommonLibrary
{
    public class CheckValue
    {
        public static string GetString(SqlDataReader reader, string collumnName)
        {
            string result = "";
            try
            {
                result = reader.GetString(reader.GetOrdinal(collumnName));
            }
            catch (System.Data.SqlTypes.SqlNullValueException)
            {
                result = "";
            }
            return result;
        }
        public static int GetInteger(SqlDataReader reader, string collumnName)
        {
            int result = -1;
            try
            {
                result = reader.GetInt32(reader.GetOrdinal(collumnName));
            }
            catch (System.Data.SqlTypes.SqlNullValueException)
            {
                result = -1;
            }
            return result;
        }
        public static float GetFloat(SqlDataReader reader, string collumnName)
        {
            float result = 0;
            try
            {
                result = reader.GetFloat(reader.GetOrdinal(collumnName));
            }
            catch (System.Data.SqlTypes.SqlNullValueException)
            {
                result = 0;
            }
            return result;
        }
        public static double GetDouble(SqlDataReader reader, string collumnName)
        {
            double result = 0;
            try
            {
                result = reader.GetDouble(reader.GetOrdinal(collumnName));
            }
            catch (System.Data.SqlTypes.SqlNullValueException)
            {
                result = 0;
            }
            return result;
        }
        public static bool GetBoolean(SqlDataReader reader, string collumnName)
        {
            bool result = true;
            try
            {
                result = reader.GetBoolean(reader.GetOrdinal(collumnName));
            }
            catch (System.Data.SqlTypes.SqlNullValueException)
            {
                result = false;
            }
            return result;
        }
        public static DateTime GetDatetime(SqlDataReader reader, string collumnName)
        {
            DateTime result = DateTime.Now;
            try
            {
                result = reader.GetDateTime(reader.GetOrdinal(collumnName));
            }
            catch (System.Data.SqlTypes.SqlNullValueException)
            {
                result = DateTime.Now;
            }
            return result;
        }
        public static int GetParamterUrl(string paramName)
        {
            int result;
            try
            {
                result = int.Parse(HttpContext.Current.Request.QueryString[paramName].ToString());
            }
            catch(Exception)
            { result = -1; }
            return result;
        }
    }
}
